<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">复审</span>
			<!--<span class="h2">推广查询</span>-->
		</div>
		<div style="margin-top: 30px;">
			<el-form ref="form" :model="form" label-width="80px" :label-position="labelPosition">
				<el-row :gutter="20">
				  <el-col :span="8">
				  	<div class="grid-content bg-purple leftdiv">
				  		<h2  class="infod">用户信息</h2>
				  		<el-form-item label="姓名">
						    <el-input v-model="form.name" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="性别">
						    <el-select v-model="values" placeholder="请选择" :disabled="true">
							    <el-option
							      v-for="item in form.options"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="身份证号">
						    <el-input v-model="form.card" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="年龄">
						    <el-input v-model="form.age" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="手机号">
						    <el-input v-model="form.tel" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="电话年限">
						    <el-input v-model="form.years" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="芝麻分">
						    <el-input v-model="form.city" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="居住地址">
						    <el-input v-model="form.address" :disabled="true"></el-input>
						</el-form-item>
						<!--<el-form-item label="QQ">
						    <el-input v-model="form.qq" :disabled="true"></el-input>
						</el-form-item>-->
						<el-form-item label="微信">
						    <el-input v-model="form.wechat" :disabled="true"></el-input>
						</el-form-item>
				  	</div>
				  </el-col>
				  <el-col :span="8">
				  	<div class="grid-content bg-purple-light rightdiv">
				  		<!--<h2 class="infod">需求信息</h2>
				  		<p class="total">还有 {{form.total}}  条需求未处理</p>
				  		<el-form-item label="借款额度">
						    <el-input v-model="form.limit" :disabled="true"></el-input>
						</el-form-item>-->
						<el-form-item label="复审结果">
						    <el-radio-group v-model="radio2" @change="change()">
							    <el-radio :label="3">同意</el-radio>
							    <el-radio :label="4">拒绝</el-radio>
							</el-radio-group>
						</el-form-item>
						<p class="total">拒绝原因：</p>
						<div >
							<el-input type="textarea" v-model="desc"></el-input>
						</div>
						<el-button type="primary"style="margin-top: 20px;" @click="Result()">确定</el-button>
				  	</div>
				  </el-col>
				  <el-col :span="8" v-if="isTrue">
				  	<div class="grid-content bg-purple-light rightdiv">
					  	<el-form ref="form" :model="form" label-width="100px">
							<el-form-item label="放款日期">
								<el-date-picker v-model="datatimes" type="date"  format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
								</el-date-picker>
							</el-form-item>
							<el-form-item label="放款期限">
								<el-input v-model="form.days" @change="add()" style="width: 70%;"></el-input>&nbsp;&nbsp;天
							</el-form-item>
							<el-form-item label="还款日期">
								<el-date-picker v-model="endtimes"  :disabled='true' type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
								</el-date-picker>
							</el-form-item>
							<el-form-item label="放款金额">
								<el-input v-model="form.money"></el-input>
							</el-form-item>
							<el-form-item label="借条平台">
								<el-select v-model="value" placeholder="请选择">
									<el-option v-for="item in optio" :key="item.value" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="对方账号">
								<el-input v-model="form.member"></el-input>
							</el-form-item>
							<el-form-item label="综合利息">
								<el-input v-model="form.refund"></el-input>
							</el-form-item>
							<el-form-item label="审核人">
								<el-input v-model="form.men"></el-input>
							</el-form-item>
						</el-form>
					</div>
				  </el-col>
				</el-row>
			</el-form>
		</div>
	</div>
</template>

<script>
	import apis from '../../../api/prouserApi'
	export default {
	name:'rehear',
    data() {
      return {
      	isTrue:false,
      	loading:false,
      	labelPosition:'left',//左对齐
      	form:{
      		total:0,//未处理多少条
      		name:'',//用户名
      		days:'',
			money:"",//放款金额
			member:"",//对方账号
			refund:"",//放款账号
			men:sessionStorage.CNName,//收款负责人
      		options:[
	      		{
	      			value: '男',
          			label: '男'
	      		},
	      		{
	      			value: '女',
          			label: '女'
	      		} 
      		],
      		card:'',//身份证
      		age:'',//年龄
      		years:'',//电话实名年限
      		city:'',//居住城市
      		address:'',//居住地址
      		qq:'',//QQ
      		wechat:'',//微信
      		limit:'',//额度
      		
      	},
      	id:"",
      	values: '',//性别
      	radio2: 2,//进度
      	desc:'',//原因
      	ProviderID:'',
  	    optio: [{
			value: '今借到',
			label: '今借到'
		}, {
			value: '米房',
			label: '米房'
		}, {
			value: '借贷宝',
			label: '借贷宝'
		},{
			value: '无忧借条',
			label: '无忧借条'
		},{
			value: '安牛有借',
			label: '安牛有借'
		}],
		value:'',//渠道
		datatimes:new Date(),//放款日期
		endtimes:"",//还款日期
		AllotID:'',
		DemandID:"",
		MemberID:""
      }
    },
    created() {
		this.ProviderID = sessionStorage.ProviderID
		this.getallotagian()
	},
	
    methods: {
    	getallotagian(){
    		this.$axios.get(apis.getallotagian + '/'+this.$route.params.id).then((res) => {
				if(res.data.isOK) {
					this.form.name = res.data.data.MemberInfo.CNName
					this.values = res.data.data.MemberInfo.Gender
					this.form.card = res.data.data.MemberInfo.CardID
					this.form.age = res.data.data.MemberInfo.Age
					this.form.tel = res.data.data.MemberInfo.Tel
					this.form.years = res.data.data.MemberInfo.TelYears
					this.form.city = res.data.data.MemberInfo.ZMScore
					this.form.address = res.data.data.MemberInfo.Address
					this.form.qq = res.data.data.MemberInfo.QQ
					this.form.wechat = res.data.data.MemberInfo.WX
//					this.form.limit = res.data.data.DemandMoney
					this.AllotID = res.data.data.Allot.ID
					this.DemandID= res.data.data.Allot.MDemandID
					this.MemberID= res.data.data.Allot.MemberID
//					this.form.total = this.form.total || res.data.data.UnAllotAmount
					this.loading = false
				} else {
					if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading =false
							this.$message.error(res.data.msg);
						}
				}
			});
    	},
    	change(){
    		if(this.radio2 == 3){
    			this.isTrue = true
    		}else if(this.radio2 == 4){
    			this.datatimes=""
    			this.form.days = ""
    			this.endtimes=""
    			this.form.money=""
    			this.value=""
    			this.form.member=""
    			this.form.refund=""
    			this.form.men=""
    			this.isTrue = false
    		}
    	},
    	add(){
				this.endtimes = new Date(this.form.days*86400000 + new Date(this.datatimes).getTime())
		},
    	Result(){
    		this.loading = true
			this.$axios.post(apis.setallotagian,{
			  "approve": {
			    "AllotID": this.AllotID,
			    "Status": this.radio2,
			    "RefuseMemo": this.desc
			  },
			  "LoanInfo": {
			  	"AllotID": this.AllotID,
			    "LoanDate":this.datatimes ,
			    "RefundDate": this.endtimes,
			    "LoanMoney": this.form.money,
			    "LoanAccountType": this.value,
			    "MemberAccountCode": this.form.member,
			    "LoanAccountCode": this.form.refund,
			    "RefundMan": this.form.men,
			    "DemandID": this.DemandID,
			    "ProviderID": this.ProviderID,
			    "MemberID": this.MemberID
			  }
			}).then(res=>{
				if(res.data.isOK) {
					this.$router.push({
							path: '/examine'
					})
				} else {
					if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
						this.$router.push({
							path: '/'
						})
					} else {
						this.loading = false
						this.$message.error(res.data.msg);
					}
				}
			})
    	}
    }
  }
</script>

<style>
	.infod{
		margin-bottom: 20px;
	}
	.total{
		height: 40px;
		line-height: 40px;
		margin-bottom: 22px;
	}
	.leftdiv{
		background: #fff;
		padding: 15px;
		border: 1px solid #ccc;
	}
	.rightdiv{
		background: #fff;
		padding: 15px;
		border: 1px solid #ccc;
	}
</style>